# pic url http://7xouub.com1.z0.glb.clouddn.com/my-python-logo.png

from qiniu import Auth, put_file, etag, urlsafe_base64_encode
import qiniu.config
#需要填写你的 Access Key 和 Secret Key
access_key = 'p2unALHk4ulr77GyrlJpQqVfSNdM0UsguvKREUNd'
secret_key = '0Tn0-BFxhS_Om1O2UbaocgyrgaBvGVVOYALeceap'


def upload_image(pic_path, pic_name):
    #构建鉴权对象
    q = Auth(access_key, secret_key)
    #要上传的空间
    bucket_name = 'media'
    #上传到七牛后保存的文件名
    key = pic_name
    #生成上传 Token，可以指定过期时间等
    token = q.upload_token(bucket_name, key, 600)
    #要上传文件的本地路径
    ret, info = put_file(token, key, pic_path)
    print('upload scs')
    assert ret['key'] == key
    assert ret['hash'] == etag(pic_path)
    return 'http://7xouub.com1.z0.glb.clouddn.com/%s'%pic_name